/**
 * 求两个数组的合集， 并集
 * */

const a = [1, 2, 3, 4, 5, 19, 10]
const b = [2, 3, 4, 7, 90, 19, 89]

function sum(a, b) {
    let newArr = []
    // 两边循环找到， 两者共同的，然后删掉一个， 最后， 两个合并一下.
    for (let i = 0; i < a.length; i++) {
        for (let j = 0; j < b.length; j++) {
            if(a[i] === b[j]){
                a.splice(i, 1)
            }
        }
    }
    console.log([...a, ...b].sort((a, b) => a - b))
    return [...a, ...b]
}
// sum(a, b)

function sumV2(a, b){
    console.log([...new Set([...a,...b])].sort((a, b) => a - b))
    return [...new Set([...a,...b])]
}
// sumV2(a, b)

//    求交集
function  unique() {
    const newArr = []
    for (let i = 0; i < a.length; i++) {
        for (let j = 0; j < b.length; j++) {
            if(a[i] === b[j]){
                console.log(a[i])
                newArr.push(a[i])
            }
        }
    }
    console.log(newArr)
    return newArr
}


// unique(a, b)
